<?php 
$seitcm_class_id = isset($_GET['class']) ? $_GET['class'] : 0;
$seitcm_class_data = seitcm_get_single_class($seitcm_class_id);
$seitcm_action = isset($_GET['action']) ? $_GET['action'] : 'list';
$seitcm_action = $seitcm_action == 'collectfee' || $seitcm_action == 'rollup' ? $seitcm_action : 'list';

if($seitcm_class_data == null)
{
	//404
}
else
{
	if($seitcm_action=='list')
	{
	?>

<div id="seitcm_wrapper_ms">
	
    <div id="seitcm_header">
    	<div id="seitcm_head_logo">
            <h1><?php _e('Sunshine Education','SEITCM') ?></h1>
            <h2><?php _e('Student list','SEITCM') ?></h2>
        </div>
        <div id="seitcm_head_menu">
        	<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=score&class=<?php echo $seitcm_class_id?>&action=examinationscores">Add exam scores</a>
        	<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=score&class=<?php echo $seitcm_class_id?>&action=list">Scores list</a>
        	<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=list">Class list</a>
        </div>
        <div class="seitcm_clearfload">
        </div>
    </div>
    
    <div class="seitcm_bigwidget_block">
		<div class="seitcm_bigwidget_block_inner">
			<table class="seitcm_grid"><tbody>
				<tr>
    				<th><?php _e('NO','SEITCM')?></th>
    				<th><?php _e('Login Name','SEITCM')?></th>
    				<th><?php _e('Real Name','SEITCM')?></th>
    				<th><?php _e('English Name','SEITCM')?></th>
    				<th><?php _e('Date of birth','SEITCM')?></th>
    				<th><?php _e('Status','SEITCM')?></th>
    				<th><?php _e('Control','SEITCM')?></th>
    			</tr>
	    		<?php
	    			$seitcm_result = seitcm_get_class_student_list($seitcm_class_id);
	    			$i=1;
	    			$ar = array(0,0,0,0);
	    			foreach ($seitcm_result as $seitcm_row)
	    			{
	    				$learnningstatus = get_user_meta($seitcm_row->ID, 'learningstatus', true);
	    				$ar[$learnningstatus-1] +=1;
	    				?>
	    				<tr>
	    					<td><?php echo $i++?></td>
	    					<td><?php echo $seitcm_row->user_login?></td>
	    					<td><?php echo get_user_meta($seitcm_row->ID, 'first_name', true) . ' ' . get_user_meta($seitcm_row->ID, 'last_name', true)?></td>
	    					<td><?php echo get_user_meta($seitcm_row->ID, 'englishname', true)?></td>
	    					<td><?php echo get_user_meta($seitcm_row->ID, 'dob', true)?></td>
	    					<td>
	    						<?php 
								global $seitcm_student_status;
			                    foreach ($seitcm_student_status as $seitcm_status){
			                        if($seitcm_status['key']==$learnningstatus) echo $seitcm_status['Value'];
			                    }
								?>
	    					</td>
	    					<td>
	    						<?php 
	    							if(!$seitcm_row->collectedfee)
	    							{
	    								?>
	    								<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=studentlist&class=<?php echo $seitcm_class_id?>&action=collectfee&regid=<?php echo $seitcm_row->id?>"><?php _e('Collect Fee','SEITCM')?></a>
	    								<?php 
	    							}
	    						?>
	    						<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=studentlist&class=<?php echo $seitcm_class_id?>&action=rollup&stuid=<?php echo $seitcm_row->ID?>"><?php _e('Rollup history','SEITCM')?></a>
	    					</td>
	    				</tr>
	    				<?php 
	    			}
		    		?>
	    	</tbody></table>
    	</div>
    </div>
    
    <div class="seitcm_bigwidget_block">
		<div class="seitcm_bigwidget_block_inner">
		    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
			<script type="text/javascript">
			      google.load("visualization", "1", {packages:["corechart"]});
			      google.setOnLoadCallback(drawChart);
			      function drawChart() {
			        var data = google.visualization.arrayToDataTable([
			          ['Student status', 'Count'],
			          <?php 
			          global $seitcm_student_status;
			          foreach ($seitcm_student_status as $seitcm_status){
							echo '[\''.$seitcm_status['Value'].'\','.$ar[$seitcm_status['key']-1].'],';
			          }
			          ?>
			        ]);
			
			        var options = {
			          title: 'Student status statitic'
			        };
			
			        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
			        chart.draw(data, options);
			      }
	    	</script>
			<div id="chart_div" style="height: 350px;"></div>
		</div>
	</div>
</div>
<?php 
	}
	else if($seitcm_action == 'collectfee')
	{
		
	}
	else if($seitcm_action == 'rollup')
	{
		$seitcm_stuid= isset($_GET['stuid']) ? $_GET['stuid'] : 0;
		$rollup_history = seitcm_get_rollup_status_list($seitcm_stuid, $seitcm_class_id);
		?>
		<div id="seitcm_wrapper_ms">
		<div id="seitcm_header">
	    	<div id="seitcm_head_logo">
	            <h1><?php _e('Sunshine Education','SEITCM') ?></h1>
	            <h2><?php echo __('Rollup history of ','SEITCM') . get_user_meta($seitcm_stuid,'first_name',true) . ' ' . get_user_meta($seitcm_stuid,'last_name',true) ?></h2>
	        </div>
	        <div id="seitcm_head_menu">
	        	<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=list">Class list</a>
	        	<a class="seitcm_button" href="admin.php?page=seitcm_class_option_menu&module=studentlist&class=<?php echo $seitcm_class_id?>">Student list</a>
	        </div>
	        <div class="seitcm_clearfload">
	        </div>
	    </div>
	    
	    <div class="seitcm_bigwidget_block">
			<div class="seitcm_bigwidget_block_inner">
				<table class="seitcm_grid"><tbody>
					<tr>
						<th><?php _e('NO','SEITCM')?></th>
						<th><?php _e('Title','SEITCM')?></th>
						<th><?php _e('Time','SEITCM')?></th>
						<th><?php _e('Checkin','SEITCM')?></th>
					</tr>
					<?php 
					$i=0;
					foreach ($rollup_history as $rollup){
					?>
					<tr>
						<td><?php echo ++$i?></td>
						<td><?php echo $rollup->title?></td>
						<td><?php echo seitcm_create_datetime_from_mysql($rollup->time)?></td>
						<td><?php echo $rollup->checkin ? 'Checkin' : 'Missed'?></td>
					</tr>
					<?php 
					}
					?>
				</tbody></table>
			</div>
		</div>
		</div>
		<?php 
	}
}
?>
